<?
require ("lib/config.php");
$msj="";
$validator=new validator("form1");
$validator->create_message("id_login","login","(*) Campo Requerido");
$validator->create_message("id_pwd","pwd","(*) Campo Requerido");

if ($_GET['ac']) {
	$usuario=new usuarios;
	$txtlogin=$_REQUEST['login'];
	$txtpwd=$_REQUEST['pwd'];

	$txtzona=$_REQUEST['oficina'];


	if ($usuario->access_login($conn, $txtlogin, $txtpwd, $txtzona)) {
		header("Location: frames.php");
	}else {
		$space ="<br>";
		$msj="Nombre De Usuario y/o Contrase&ntilde;a Incorrectos";
	}
}
if ($_GET['st']) {
	$msj = "Usuario Inactivo";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>Sistema de Experticias</title>
<head><link rel="shortcut icon" href="images/favicon.ico" >
      <link rel="icon" href="images/animated_favicon1.gif" type="image/gif" ></head>
<link href="css/estilos.css" type="text/css" rel="stylesheet">

<script src="js/json.js" type="text/javascript"></script>
<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/scriptaculous.js" type="text/javascript"></script>

<? $validator->print_script(); ?>
</head>
<body>
<div id="contenedor_banner">
	<div id="cabecera"></div>
<!--	<div id="cabecera1"></div>
	<div id="cabecera2"></div>
	<div id="cabecera3"></div>--!>
</div>
<div id="contenedor_contenido">
	<div id="cuerpo">
		<div id="principal">
        <div id="msj_login">CONTROL DE ACCESO</div>		
<br /><br />
<? if(!empty($msj)){ ?><div id="msj" style="display:none;"><?=$msj?></div><? } ?>
<br /><br /><br />
<div style="margin-left:auto; margin-right:auto; padding-left:20px">

      <form action="?ac=lg" method="POST" name="form1" >

        <table id="login" border="0" cellpadding="1" cellspacing="0" align="center">
          <tr>
            <td>Oficina:&nbsp;</td>
            <td colspan="2"><input name="oficina" id="oficina" onChange="" type="text" size="10" maxlength="50" class="textbox"/></td>
            <td colspan="2"><input name="oficina2" id="oficina2" type="hidden"></td>
            <td colspan="2"><input name="id_oficina" id="id_oficina" type="hidden"></td>
          </tr>

          <tr>
            <td width="72">Usuario:&nbsp;</td>
            <td width="143"><input name="login" id="login" type="text" size="23" maxlength="50" class="textbox"/>
              &nbsp;
            <?=$validator->show("id_login");?></td>
			<td></td>
          </tr>
          <tr>
            <td><div align="right" class="logintext">Contrase&ntilde;a:&nbsp;</div></td>
            <td ><input type="password" name="pwd" size="23" maxlength="50"  class="textbox"/>
              &nbsp;
              <?=$validator->show("id_pwd");?></td>
			<td></td>
	    </tr>

          <tr>
            <td></td>
            <td colspan="2"><input name="enviar" type="button" class="boton_login" style="cursor:pointer" value="Login" onclick="<?=$validator->validate()?>"/></td>
          </tr>
        </table>
        <div align="center">
          <br>
          <?= $space ?>
        </div>
      </form>

<br /><br /><br />


		</div>
	</div>
	<div id="pie">Version 1.0</div>
</div>


<script type="text/javascript">
<?=(!empty($msj)) ? "Effect.Appear('msj',{duration:1.2});\n" : ""?>
Event.observe(window, "keypress", function (e) { if(e.keyCode == Event.KEY_RETURN){ validate(); } });
Event.observe(window, "load", function () { document.form1.oficina.focus(); });

function busca_oficina()
{
	var JsonAux;
	var oficina = document.getElementById('oficina').value;
	document.getElementById("oficina2").value = '';
	document.getElementById("id_oficina").value = '';
	if(oficina!=""){
		JsonAux={"Oficina":oficina};
		var url = 'BuscarOficina.php';
		var pars = 'JsonEnv=' + JsonAux.toJSONString();
		var Request = new Ajax.Request(
			url,
			{
				method: 'post',
				parameters: pars,
		//		asynchronous:true, 
				onComplete:function(request){
					var JsonRec = eval( '(' + request.responseText + ')');
					if(JsonRec){
						document.getElementById("oficina2").value = JsonRec[0]['N'];
						document.getElementById("id_oficina").value = JsonRec[0]['ID'];
						
					}
				}
			}
		); 
	} else {
		document.getElementById("oficina2").value = '';
		document.getElementById("id_oficina").value = '';
	}

}
</script>

</body>
</html>
